<script>
function fetchUgokamKampanje(forma){
	var ul_sa = document.getElementById("ugokam_kampanja_sa");
	var ul_bez= document.getElementById("ugokam_kampanja_bez");
	
	// SA
	var inpt = document.createElement("input");
	inpt.type="hidden";
	inpt.name = "kampanja_sa";
	var sel = ul_sa.getElementsByTagName("select");
	for(var i=0; i<sel.length; i++){
		if(sel[i].value>0)
		inpt.value += ";"+sel[i].value;
	}
	inpt.value = inpt.value.substr(1);
	forma.appendChild(inpt);
	
	// BEZ
	var inpt = document.createElement("input");
	inpt.type="hidden";
	inpt.name = "kampanja_bez";
	var sel = ul_bez.getElementsByTagName("select");
	for(var i=0; i<sel.length; i++){
		if(sel[i].value>0)
		inpt.value += ";"+sel[i].value;
	}
	inpt.value = inpt.value.substr(1);
	forma.appendChild(inpt);
}
</script>
<style>
#advanceSearch form{
	margin:2px;
}
#advanceSearch form .expand,
#advanceSearch form .collapse{
	width:16px;
	height:16px;
	float:right;
	overflow:hidden;
	margin:-8px -8px 0px 0px;
	position:relative;
	
	text-indent:-100em;
	font-weight:bolder;
	text-decoration:none;
	
	background-color:transparent;
	border:none;
	background-position:center center;
	background-repeat:no-repeat;
	cursor:pointer;
}
#advanceSearch form .expand{background-image:url(gui/icons/maximize.gif);}
#advanceSearch form .collapse{background-image:url(gui/icons/minimize.gif);}
#advanceSearch form fieldset{
	clear:both;
}
ul#BezKampanjaUL{
	margin:0px;
	padding:0px;
	list-style-type:none;
}
ul#BezKampanjaUL li{
	margin:0px;
	padding:0px;
}
ul#BezKampanjaUL li{
	clear:both;
}
#advKomitentSearchAdresa{
	width:470px;
}
#advKomitentSearchAdresa label{
	float:left;
	display:block;
	padding-top:8px;
	text-align:right;
	width:90px;
}
#advKomitentSearchAdresa legend[onclick]{
	cursor:pointer;
}
#advKomitentSearchAdresa select#kategorija{
	width:200px;
}
#advKomitentSearchAdresa select#delatnost{
	width:300px;
}
#advKomitentSearchAdresa fieldset{
	float:left;
	clear:both;
}
#advKomitentSearchAdresa fieldset label{
	width:80px;
}
#advKomitentSearchAdresa ul.view_status_list{
	float:left;
	margin:0px;
	padding:0px;
	list-style-type:none;
}
#advKomitentSearchAdresa ul.view_status_list li{
	display:block;
	float:left;
	clear:both;
	margin:0px;
	padding:0px;
}
#advKomitentSearchAdresa ul.view_status_list li label{
	width:auto;
	text-align:left;
}

#advKomitentSearchDelatnosti{
	width:260px;
	margin-left:2px;
}
#advKomitentSearchDelatnosti select{
	width:220px;
}
#advKomitentSearchDelatnosti label{
	width:80px;
}
#advKomitentSearchKomAttribute{
	margin:2px 0px 0px 2px;
	width:260px;
}
#advKomitentSearchKomProfile{
	width:250px;
}
#advKomitentSearchKomBrand{
	width:270px;
}
#advKomitentSearchUgoKam{
	width:600px;
}
#advKomitentSearchUgoKam label{
	float:left;
	display:block;
	text-align:right;
	width:70px;
	margin:5px 0px;
}
#advKomitentSearchUgoKam fieldset ul li input,
#advKomitentSearchUgoKam legend input{
	float:none;
	margin:0px 5px;
	border:none;
	background-color:transparent;
	width:16px;
	height:16px;
	padding:0px;
	cursor:pointer;
}
#advKomitentSearchUgoKam fieldset ul li input{
	float:left;
	margin:5px 0px;
}
#advKomitentSearchUgoKam fieldset ul{
	list-style-type:none;
	margin:0px;
	padding:0px;
}
#advKomitentSearchUgoKam fieldset ul li{
	margin:0px;
	padding:0px;
	clear:both;
}
#onoffLista{
	float:left;
	list-style-type:none;
	margin:0px;
	padding:2px;
	background:#f7f7e2 url(gui/vgrad.gif) repeat-x 0px bottom;
	border:1px solid #aaa;
}
#onoffLista li{
	display:block;
	float:left;
	margin:2px;
	padding:2px 4px;
	cursor:pointer;
	
	background:transparent;
	color:#000;
	border-right:1px dotted #aaa;
	
	font-weight:normal;
	font-size:11px;
}
#onoffLista li:last-child{
	border-right:none;
}
#onoffLista li.on{
	background:{{$highlight}};
	color:{{$highlighttext}};
	font-weight:bolder;
}
#pretraga h3{
	font-weight:normal;
}
#pretraga h3 i{
	font-weight:bolder;
	font-family:Georgia, "Times New Roman", Times, serif;
}
#advanceSearch form fieldset.left{
	float:left;
	clear:none;
}
</style>
<div id="advanceSearch">
<br clear="all" />
<!-- ADRESA DELATNOST -->
<form pos="0;25" class="area" method="post" name="advKomitentSearchAdresa" id="advKomitentSearchAdresa" action="javascript:void(0)" onsubmit="advanceKomitentSearch(this)">
	<h3>...po adresi-delatnosti</h3>
	<input type="hidden" name="submitted" value="1" />
	<input type="hidden" name="page" value="1" />
	<fieldset>
	  <legend>Adresa:</legend>
	  	{{$adresa}}
	</fieldset><br clear="all" />
	<fieldset>
		<legend>Delatnost:</legend>
		<label for="kategorija">Kategorija:</label>
		<select name="kategorija" id="kategorija" onchange="advSearchFilterDelatnosti(this)">
			<option value="-1">---</option>
			{{%loop start kat_id}}
			<option value="{{$kat_id}}">{{$kat_name}}</option>
			{{%loop end}}
		</select><br clear="all" />
		<label for="delatnost">Delatnost:</label>
		<select name="delatnost" id="delatnost">
			<option value="-1">---</option>
			{{%loop start del_id}}
			<option value="{{$del_id}}" katid="{{$delkat_id}}">{{$del_name}}</option>
			{{%loop end}}
		</select>
	</fieldset><br clear="all" />
	<fieldset>
		<legend>BEZ:</legend>
		<div style="display:block">
			<ul class="view_status_list">
				{{%loop start vsid}}
				<li>
					<input type="checkbox" name="vs_{{$vsid}}" id="vs_{{$vsid}}" />
					<label for="vs_{{$vsid}}">{{$vsname}}</label>
				</li>
				{{%loop end}}
			</ul>
			<div style="float:left; margin-left:5px; width:280px; overflow:hidden">
				<div class="region left" title="sastanak">
				
					<label for="bez_sastanak_od" style="width:auto;">od:</label>
					<input type="text" class="dateInput" name="bez_sastanak_od" id="bez_sastanak_od" />
					<input type="button" class="datePicker" onclick="displayDatePicker('bez_sastanak_od',this)" />
					<label for="bez_sastanak_do" style="width:30px">do:</label>
					<input type="text" class="dateInput" name="bez_sastanak_do" id="bez_sastanak_do" />
					<input type="button" class="datePicker" onclick="displayDatePicker('bez_sastanak_do',this)" />
				
				</div>
				
				<br clear="all" />
				<div class="region left" title="kampanje">
					<input type="button" class="novi transparentbutton" value="" onclick="advSearchBezKampanjaAdd()" />
					<input type="button" class="delete transparentbutton" value="" onclick="advSearchBezKampanjaRemove()" />
					<input type="hidden" name="bez_kampanja_length" id="bez_kampanja_length" value="1" />
					<br clear="all" />
					<ul id="BezKampanjaUL">
						<li>
							<select name="bez_kampanja_1" id="bez_kampanja_1">
								<option value="-1">---</option>
								{{%loop start kampanja_id}}
								<option value="{{$kampanja_id}}">{{$kampanja_ime}}</option>
								{{%loop end}}
							</select>
						</li>
					</ul>
					<br clear="all" />
				</div>
			</div><br clear="all" />
		</div>
	</fieldset><br clear="all" />
	<label for="sort">Sortiraj po:</label>
	<select name="sort" id="sort">
		<option value="1">nazivu</option>
		<option value="2">adresi</option>
	</select>
	<input name="sbt" type="button" onclick="this.parentNode.elements['page'].value=1; advanceKomitentSearch(this.parentNode,event)" value="traži..." />
</form>
<!-- DELATNOST NAZIV -->
<form pos="435;25" class="area" method="post" name="advKomitentSearchDelatnosti" id="advKomitentSearchDelatnosti" action="javascript:void(0)" onsubmit="advanceKomitentSearch(this)">
	<h3>...po delatnosti-nazivu</h3>
	<input type="hidden" name="submitted" value="2" />
	<fieldset>
		<legend>Delatnost:</legend>
		<label for="kategorija">Kategorija:</label>
		<select name="kategorija" id="kategorija" onchange="advSearchFilterDelatnosti(this)">
			<option value="-1">---</option>
			{{%loop start kat_id}}
			<option value="{{$kat_id}}">{{$kat_name}}</option>
			{{%loop end}}
		</select><br clear="all" />
		<label for="delatnost">Delatnost:</label>
		<select name="delatnost" id="delatnost">
			{{%loop start del_id}}
			<option value="{{$del_id}}" katid="{{$delkat_id}}">{{$del_name}}</option>
			{{%loop end}}
		</select><br clear="all" />
		
		<label for="filter_komitent">Komitent:</label><input type="text" name="filter_komitent" id="filter_komitent" value="{{$filter_komitent}}" />
	</fieldset>
	<input type="submit"  value="traži..." />
</form>
<!-- ATRIBUT -->
<form pos="600;25" class="area" method="post" name="advKomitentSearchKomAttribute" id="advKomitentSearchKomAttribute" action="javascript:void(0)" onsubmit="advanceKomitentSearch(this)">
	<h3>...po atributu komitenta</h3>
	<input type="hidden" name="submitted" value="3" />
	<fieldset style="float:left">
	  <legend>Aribut komitenta:</legend>
	  
		<label for="attrib" class="left">atribut:</label>
		<select name="attrib" id="attrib">
			{{%loop start attrib_id}}
			<option value="{{$attrib_id}}">{{$attrib_name}}</option>
			{{%loop end}}
		</select>
		<input type="text" name="keyword" style="width:90px" />
	</fieldset>
	
	<input type="submit" value="traži..." />
</form>
<!-- PROFIL -->
<form pos="0;100" class="area" method="post" name="advKomitentSearchKomProfile" id="advKomitentSearchKomProfile" action="javascript:void(0)" onsubmit="advanceKomitentSearch(this)">
	<h3>...po tekstu u profilu</h3>
	<input type="hidden" name="submitted" value="4" />
	<label class="left" for="kword">ključna reč</label>
	<input type="text" name="kword" id="kword" />
	
	<br clear="all" />
	<fieldset>
		<legend>Adresa:</legend>
		<label class="left" for="komprofile_mesto" style="width:65px;">grad:</label>
		<select name="komprofile_mesto" id="komprofile_mesto" onchange="updateLokacijaSelects(this,1,Array('komprofile_lokops','komprofile_naselje'))">
			<option value="-1">---</option>
			{{%loop start grad_id}}
			<option value="{{$grad_id}}">{{$grad_name}}</option>
			{{%loop end}}
		</select><br clear="all" />
		<label class="left" for="komprofile_lokops" style="width:65px;">lok.opština:</label>
		<select name="komprofile_lokops" id="komprofile_lokops" onchange="updateLokacijaSelects(this,2,Array('komprofile_mesto','komprofile_naselje'))">
			<option value="-1" parent="-1">---</option>
			{{%loop start lokops_id}}
			<option value="{{$lokops_id}}" parent="{{$lokops_parent}}">{{$lokops_name}}</option>
			{{%loop end}}
		</select><br clear="all" />
		<label class="left" for="komprofile_naselje" style="width:65px;">naselje:</label>
		<select name="komprofile_naselje" id="komprofile_naselje" onchange="updateLokacijaSelects(this,3,Array('komprofile_mesto','komprofile_lokops'))">
			<option value="-1" parent="-1">---</option>
			{{%loop start naselje_id}}
			<option value="{{$naselje_id}}" parent="{{$naselje_parent}}">{{$naselje_name}}</option>
			{{%loop end}}
		</select>
	</fieldset>
	
	<br clear="all" />
	<input type="submit" value="traži" />
</form>
<!-- BRAND -->
<form pos="0;300" class="area" method="post" name="advKomitentSearchKomBrand" id="advKomitentSearchKomBrand" action="javascript:void(0)" onsubmit="advanceKomitentSearch(this)">
	<h3>...po brand-u</h3>
	<input type="hidden" name="submitted" value="5" />
	<label for="kword" class="left">naziv brand-a:</label>
	<input type="text" name="kword" id="kword" />
	<input type="submit" value="traži" />
</form>
<!-- UGOVORI/KAMPANJE -->
<form pos="0;600" class="area" method="post" name="advKomitentSearchUgoKam" id="advKomitentSearchUgoKam" action="javascript:void(0)" onsubmit="fetchUgokamKampanje(this); advanceKomitentSearch(this)">
	<h3>...po ugovorima/kampanjama</h3>
	<input type="hidden" name="submitted" value="6" />
	
	<fieldset class="left">
		<legend>Adresa:</legend>
		{{$adresa_ugokam}}
	</fieldset>
	<fieldset class="left">
		<legend>Bez sastanka:</legend>
		<label for="ugokam_sastanak_od" style="width:25px">od:</label>
		<input type="text" class="dateInput" name="ugokam_sastanak_od" id="ugokam_sastanak_od" />
		<input type="button" class="datePicker" onclick="displayDatePicker('ugokam_sastanak_od',this)" />
		<label for="ugokam_sastanak_do" style="width:25px;">do:</label>
		<input type="text" class="dateInput" name="ugokam_sastanak_do" id="ugokam_sastanak_do" />
		<input type="button" class="datePicker" onclick="displayDatePicker('ugokam_sastanak_do',this)" />
	</fieldset>
	
	<br clear="all" />
	<br />
	<fieldset class="left">
		<legend><input type="button" class="novi" onclick="var ul=this.parentNode.parentNode.getElementsByTagName('ul')[0]; var cl=ul.getElementsByTagName('li')[0].cloneNode(true); ul.appendChild(cl);" />imaju ugovor u...</legend>
		<ul id="ugokam_kampanja_sa">
			<li>
				<select>
					<option value="-1">---</option>
					{{%loop start kampanja_id}}
					<option value="{{$kampanja_id}}">{{$kampanja_ime}}</option>
					{{%loop end}}
				</select>
				<input type="button" class="delete" onclick="if(this.parentNode.parentNode.getElementsByTagName('li').length>1){if(confirm('Da li želite da obrišete kampanju?')){this.parentNode.parentNode.removeChild(this.parentNode)}}" />
			</li>
		</ul>
	</fieldset>
	<fieldset class="left">
		<legend><input type="button" class="novi" onclick="var ul=this.parentNode.parentNode.getElementsByTagName('ul')[0]; var cl=ul.getElementsByTagName('li')[0].cloneNode(true); ul.appendChild(cl);" />a nemaju u...</legend>
		<ul id="ugokam_kampanja_bez">
			<li>
				<select>
					<option value="-1">---</option>
					{{%loop start kampanja_id}}
					<option value="{{$kampanja_id}}">{{$kampanja_ime}}</option>
					{{%loop end}}
				</select>
				<input type="button" class="delete" onclick="if(this.parentNode.parentNode.getElementsByTagName('li').length>1){if(confirm('Da li želite da obrišete kampanju?')){this.parentNode.parentNode.removeChild(this.parentNode)}}" />
			</li>
		</ul>
	</fieldset>
	
	<input type="submit" value="traži" />
</form>

<br clear="all" />
<div id="pretraga"></div>
</div>
<script>
// set default grad to Beograd
var defaultGrad = 45;
var g = document.getElementById("grad_komitent");
if(g){
	var opts = g.options;
	for(var i=0; i<opts.length; i++){
		if(parseInt(opts[i].value)==defaultGrad){
			opts[i].selected=true;
		}else{
			opts[i].selected=false;
		}
	}
	updateSelectsAdresa(g,'grad');
}
</script>
<script>
var cheight = 10;

var as = document.getElementById("advanceSearch");
var forms=as.getElementsByTagName("form");
var lista = document.createElement("ul");
lista.id = "onoffLista";
as.insertBefore(lista,as.childNodes[0]);

if(forms.length>0){
	for(var i=0; i<forms.length; i++){
		var li = document.createElement("li");
		var h3 = forms[i].getElementsByTagName("h3")[0];
		li.innerHTML = h3.innerHTML;
		li._forma = forms[i]
		lista.appendChild(li);
		li.onclick = function(){
			this.className = this.className==""?"on":"";
			this._forma.style.display = this._forma.style.display=='block'?"none":"block";
		}
		
		/*
		forms[i].setAttribute("_fullHeight",forms[i].offsetHeight);
		var pos = forms[i].getAttribute("pos");
		pos = pos.split(";");
		forms[i].style.left = pos[0]+"px";
		forms[i].style.top  = pos[1]+"px";
		
		var btn = document.createElement("input");
		forms[i].insertBefore(btn,forms[i].childNodes[0]);
		btn.type="button"
		btn.className = "collapse";
		this.title = "minimize";
		btn.value = "+";
		btn.onclick = function(){
			var form = this.parentNode;
			var ffh = form.getAttribute("_fullHeight");
			var fh = form.style.minHeight;
			if(parseInt(fh) < ffh){
				this.className = "collapse";
				this.title = "minimize";
				form.style.minHeight = ffh+"px";
			}else{
				this.className = "expand";
				this.title = "maximize";
				form.style.maxHeight = cheight+"px";
			}
		}
		
		//forms[i].style.height = cheight+"px"
		forms[i].style.minHeight = forms[i].getAttribute("_fullHeight")+"px"
		*/
		forms[i].style.display = "none";
	}
}
</script>